package operation;

import book.List.bookList;
import book.List.book ;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:岁亮亮
 * Date:2024-01-08
 * TIME:19:25
 */
public class modoperation implements IOoperation {
    public static void menu(){
        System.out.println("****************");
        System.out.println("1 书名");
        System.out.println("2 作者");
        System.out.println("3 类型");
        System.out.println("4 价格");
        System.out.println("****************");
    }

    @Override
    public void work(bookList bookList) {
        System.out.println("修该图书");
        System.out.println("请输入要修改的图书书名");
        Scanner scanner=new Scanner(System.in);
        String str=scanner.nextLine();
        int pos=-1;
        int endnumber=bookList.getUsesize();
        for (int i = 0; i < endnumber; i++) {
            book book=bookList.getBook(i);
            if(book.getName().equals(str)){
                pos=i;break;
            }
        }
        if(pos==-1){
            System.out.println("没有找到你要修改的图书");
        }
        else{
               menu();
                System.out.println("请输入你要修改的内容序号");
                int ret=scanner.nextInt();
                if(ret==1){
                    System.out.println("请输入你要修改的书名");
                    Scanner scanner1=new Scanner(System.in);
                    String str2=scanner1.nextLine();
                    book book=bookList .getBook(pos);
                    book.setName(str2);
                    bookList .setBooks(pos,book);
                    System.out.println("修改成功");

                }
                else if(ret==2){
                    System.out.println("请输入你要修改的图书的作者");
                    Scanner scanner2=new Scanner(System.in);
                    String str2=scanner2.nextLine();
                    book book=bookList .getBook(pos);
                    book.setAuthor(str2) ;
                    bookList .setBooks(pos,book);
                    System.out.println("修改成功");
                }
                else if(ret==3){
                    System.out.println("请输入你要修改的图书的类型");
                    Scanner scanner3=new Scanner(System.in);
                    String str2=scanner3.nextLine();
                    book book=bookList .getBook(pos);
                    book.setWhere(str2) ;
                    bookList .setBooks(pos,book);
                    System.out.println("修改成功");

                }
                else if(ret==4){
                    System.out.println("请输入你要修改的图书价格");
                    Scanner scanner4=new Scanner(System.in);
                    int str2=scanner4.nextInt();
                    book book=bookList .getBook(pos);
                    book.setPrice(str2) ;
                    bookList .setBooks(pos,book);
                    System.out.println("修改成功");
                }
                else{
                    System.out.println("输入有问题重新输入");
                }

            }

        }


    }
